﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;

namespace epk23.PartIIProject
{
    interface UIAction
    {
        void undo();
        void redo();
    }
    class MoveNodeAction : UIAction
    {
        MachineGraph graph;
        ConcreteNode node;
        Point startPoint;
        Point endPoint;

        public MoveNodeAction(ConcreteNode node, Point startPoint, Point endPoint, MachineGraph graph)
        {
            this.graph = graph;
            this.node = node;
            this.startPoint = startPoint;
            this.endPoint = endPoint;
        }

        public void undo()
        {
            graph.moveNode(node, startPoint.X, startPoint.Y);

        }

        public void redo()
        {
            graph.moveNode(node, endPoint.X, endPoint.Y);
        }
    }

    class MoveArrowAction : UIAction
    {
        GraphArrow arrow;
        RuleNode oldEndNode;
        RuleNode newEndNode;

        public MoveArrowAction(GraphArrow arrow, RuleNode oldEndNode, RuleNode newEndNode)
        {
            this.arrow = arrow;
            this.oldEndNode = oldEndNode;
            this.newEndNode = newEndNode;
        }

        public void undo()
        {
            arrow.setEndNode(oldEndNode);
        }

        public void redo()
        {
            arrow.setEndNode(newEndNode);
        }
    }

    class AddRemoveNodeAction : UIAction
    {
        MachineGraph oldGraph;
        MachineGraph newGraph;
        MachineWindow window;
        Canvas canvas;


        public AddRemoveNodeAction(MachineGraph oldGraph, MachineGraph newGraph, MachineWindow window, Canvas canvas)
        {
            this.oldGraph = oldGraph;
            this.newGraph = newGraph;
            this.window = window;
            this.canvas = canvas;
        }

        public void undo()
        {
            window.changeGraph(oldGraph);
            RuleNode.graph = oldGraph;
            oldGraph.refreshGraph();
        }

        public void redo()
        {
            window.changeGraph(newGraph);
            RuleNode.graph = newGraph;
            newGraph.refreshGraph();
        }
    }

    class AddNodeAction : UIAction
    {
        public void undo()
        {

        }

        public void redo()
        {
        }
    }

    class SetStartNodeAction : UIAction
    {
        private RuleNode oldStartNode;
        private RuleNode newStartNode;
        private MachineGraph graph;

        public SetStartNodeAction(RuleNode oldStartNode, RuleNode newStartNode, MachineGraph graph)
        {
            this.oldStartNode = oldStartNode;
            this.newStartNode = newStartNode;
            this.graph = graph;
        }

        public void undo()
        {
            graph.setStartNode(oldStartNode);
        }

        public void redo()
        {
            graph.setStartNode(newStartNode);
        }
    }
}
